<template>
  <div class="pop-dialog-container">
    <div class="pop-dialog-main">
      <el-form :inline="true" :model="searchParams">
        <el-form-item label="企业名称" prop="enterpriseName">
          <el-input v-model="searchParams.enterpriseName" placeholder="请选择企业名称" readonly="readonly">
            <i slot="suffix" class="el-input__icon el-icon-search" @click="findEnterprise"></i>
          </el-input>
        </el-form-item>
        <el-form-item label="岗位名称">
            <el-input v-model="searchParams.jobTitle" placeholder="请输入岗位名称" maxlength="255"></el-input>
        </el-form-item>
        <el-form-item label="部门名称" prop="departmentName">
          <el-input v-model="searchParams.departmentName" placeholder="请选择部门名称" readonly="readonly">
            <i slot="suffix" class="el-input__icon el-icon-search" @click="findDepartment"></i>
          </el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="onSearch">查询</el-button>
          <el-button @click="onReset">重置</el-button>
        </el-form-item>
      </el-form>

      <el-table
        :data="pageData.list"
        border
        v-loading="pageData.loading"
        size="mini"
        header-cell-class-name="table-header-cell-font"
        cell-class-name="table-cell-font"
        @row-dblclick="jobDescriptionSelected">
        <el-table-column prop="enterpriseName" label="企业名称" width="100"></el-table-column>
        <el-table-column prop="jobTitle" label="岗位名称" width="120"></el-table-column>
        <el-table-column prop="departmentName" label="部门名称" width="100"></el-table-column>
        <el-table-column prop="workLocation" label="工作地点" width="80"></el-table-column>
        <el-table-column prop="jobType" label="岗位类型" width="80">
          <template v-slot="{ row }">
            <div v-if="row.jobType === 10">全职</div>
            <div v-if="row.jobType === 20">兼职</div>
            <div v-if="row.jobType === 30">实习</div>
          </template>
        </el-table-column>
        <el-table-column label="岗位职责" width="120">
          <template v-slot="{ row }">
            <div class="ellipsis">
              {{ row.responsibilities }}
            </div>
          </template>
        </el-table-column>
        <el-table-column label="岗位要求" width="120">
          <template v-slot="{ row }">
            <div class="ellipsis">
              {{ row.requirement }}
            </div>
          </template>
        </el-table-column>
        <el-table-column prop="salaryRange" label="薪资范围" width="120">
          <template v-slot="{ row }">
            <div v-if="row.salaryRange === 1">3000~5000</div>
            <div v-if="row.salaryRange === 2">5001~10000</div>
            <div v-if="row.salaryRange === 3">10001~20000</div>
            <div v-if="row.salaryRange === 4">20001~30000</div>
            <div v-if="row.salaryRange === 5">30000以上</div>
          </template>
        </el-table-column>
        <el-table-column prop="postingDate" label="发布日期" width="120"></el-table-column>
        <el-table-column prop="closingDate" label="截止日期" width="120"></el-table-column>
        <el-table-column prop="headCount" label="招聘人数" width="80"></el-table-column>
        <el-table-column prop="status" label="状态" width="80">
          <template v-slot="{ row }">
            <div v-if="row.status === 10">开放</div>
            <div v-if="row.status === 20">关闭</div>
          </template>
        </el-table-column>
      </el-table>
      <div class="table-pagination">
        <el-pagination
          @current-change="paginationChange"
          :current-page="pageData.current"
          :page-sizes="pageData.pageSizes"
          :page-size="pageData.size"
          background
          layout="total, prev, pager, next, jumper"
          :total="pageData.count">
        </el-pagination>
      </div>
    </div>
    <div class="pop-dialog-footer">
      <el-row>
        <el-col :span="11" :offset="6">
          <div class="form-button-container">
            <el-button type="primary" @click="onBack">关闭</el-button>
          </div>
        </el-col>
      </el-row>
    </div>
    <el-dialog :visible.sync="enterpriseSelectorVisible" v-if="enterpriseSelectorVisible" title="企业信息选择器(双击行选中)" :top="dialogTop" :width="dialogWidth" :append-to-body="true">
      <enterprise-selector @enterprise-selected-event="handleEnterpriseSelectedEvent">
      </enterprise-selector>
    </el-dialog>
    <el-dialog :visible.sync="departmentSelectorVisible" v-if="departmentSelectorVisible" title="部门信息选择器(双击行选中)" :top="dialogTop" :width="dialogWidth" :append-to-body="true">
      <department-selector @department-selected-event="handleDepartmentSelectedEvent">
      </department-selector>
    </el-dialog>
  </div>
</template>

<script>
import jobDescriptionApi from '@/api/jobDescriptionApi'
import EnterpriseSelector from "@/views/enterprise/EnterpriseSelector.vue";
import DepartmentSelector from "@/views/department/DepartmentSelector.vue";
import listQueryMixin from '@/mixins/listQueryMixin'
export default {
  name: 'JobDescriptionSelector',
  components: {EnterpriseSelector,DepartmentSelector,},
  mixins: [
    listQueryMixin
  ],
  data () {
    return {
      searchParams: {
        enterpriseId: '',
        enterpriseName: '',
        jobTitle: '',
        departmentId: '',
        departmentName: '',
      },
      enterpriseSelectorVisible: false,
      departmentSelectorVisible: false,
    }
  },
  methods: {
    getPageData (p) {
      return jobDescriptionApi.find(p)
    },
    onSearch () {
      this._getPageData()
    },
    onReset () {
      this.searchParams = {
        enterpriseId: '',
        enterpriseName: '',
        jobTitle: '',
        departmentId: '',
        departmentName: '',
      }
      this.pageData.pageIndex = 1
      this._getPageData()
    },
    jobDescriptionSelected (row) {
      this.$emit('job-description-selected-event', {
        jobDescriptionId: row.id,
        jobDescriptionName: row.jobTitle,
      })
    },
    findEnterprise () {
      this.enterpriseSelectorVisible = true
    },
    handleEnterpriseSelectedEvent (selectedEnterprise) {
      this.enterpriseSelectorVisible = false
      if (selectedEnterprise && 'enterpriseId' in selectedEnterprise && this.searchParams.enterpriseId !== selectedEnterprise['enterpriseId']) {
        this.searchParams.enterpriseId = selectedEnterprise['enterpriseId']
        this.searchParams.enterpriseName = selectedEnterprise['enterpriseName']
      }
    },
    findDepartment () {
      this.departmentSelectorVisible = true
    },
    handleDepartmentSelectedEvent (selectedDepartment) {
      this.departmentSelectorVisible = false
      if (selectedDepartment && 'departmentId' in selectedDepartment && this.searchParams.departmentId !== selectedDepartment['departmentId']) {
        this.searchParams.departmentId = selectedDepartment['departmentId']
        this.searchParams.departmentName = selectedDepartment['departmentName']
      }
    },
    onBack () {
      this.$emit('job-description-selected-event')
    }
  }
}
</script>

<style lang="scss">
</style>
